import 'package:demo/theme/app_colors.dart';
import 'package:demo/theme/app_text_theme.dart';
import 'package:flutter/material.dart';
import 'package:flutter/widgets.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';

import 'package:get/get.dart';

import '../../../widgets/line_horizontal.dart';
import 'add_bank_controller.dart';

class AddBankView extends GetView<AddBankController> {
  const AddBankView({Key? key}) : super(key: key);
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      backgroundColor: Color_bg,
      appBar: AppBar(title: const Text('添加银行卡')),
      body: SingleChildScrollView(
        child: Column(
          crossAxisAlignment : CrossAxisAlignment.start,
          children: [
            SizedBox(height: 15.w),
            const LineHorizontal(),
            Container(
              padding: EdgeInsets.symmetric(horizontal: 15.w),
              color: Color_white,
              child: Column(children: [
                buildName(),
                const LineHorizontal(),
                buildBank(),
                const LineHorizontal(),
                buildBankNum(),
                const LineHorizontal(),
                buildPhone(),
                const LineHorizontal(),
                buildCode(),
                const LineHorizontal(),
              ]),
            ),
            const LineHorizontal(),
            Text('注: 每月还款日自动从银行卡扣款，请保证当日余额充足。',style: text_grey_10).marginOnly(top: 15.w,bottom:30.w,left: 15.w),
            RawMaterialButton(
              highlightColor: Colors.transparent, // 透明色
              splashColor: Colors.transparent, // 透明色
              highlightElevation: 0,
              elevation: 0,
              fillColor: Color_main,
              shape : RoundedRectangleBorder(borderRadius : BorderRadius.all(Radius.circular(22.w))),
              constraints: BoxConstraints.tightFor(width: Get.width - 60.w, height: 44.w),
              child: Text('提交',style: text_white_14),
              onPressed: ()=> controller.submit(),
            ).marginOnly(left: 30.w,bottom: 15.w),
          ],
        ),
      ),
    );
  }

  Widget buildName() {
    return Row(
      mainAxisAlignment : MainAxisAlignment.spaceBetween,
      children: [
        Text('姓名',style: text_131732_14),
        Expanded(
          child: TextField(
            maxLength: 20,
            controller: controller.nameController,
            textAlign: TextAlign.right,
            style: text_131732_14,
            decoration: InputDecoration(
              prefixText: "  ",
              isDense: true,
              contentPadding: EdgeInsets.symmetric(vertical: 12.w),
              counterText: "", // 去掉底部计数
              enabledBorder:  const UnderlineInputBorder(borderSide: BorderSide.none), //无焦点时状态
              focusedBorder:  const UnderlineInputBorder(borderSide: BorderSide.none), //有焦点时状态
              hintText: '请输入姓名',
              hintStyle: text_grey_14,
            ),
          ),
        ),
      ],
    );
  }
  Widget buildBank() {
    return Row(
      children: [
        Text('开户银行',style: text_131732_14),
        Expanded(
          child: TextField(
            maxLength: 20,
            textAlign: TextAlign.right,
            style: text_131732_14,
            readOnly: true,
            controller: controller.bankController,
            onTap: () => controller.chooseBank(),
            decoration: InputDecoration(
              prefixText: "  ",
              isDense: true,
              contentPadding: EdgeInsets.symmetric(vertical: 12.w),
              counterText: "", // 去掉底部计数
              enabledBorder:  const UnderlineInputBorder(borderSide: BorderSide.none), //无焦点时状态
              focusedBorder:  const UnderlineInputBorder(borderSide: BorderSide.none), //有焦点时状态
              hintText: '请选择开户行',
              hintStyle: text_grey_14,
            ),
          ),
        ),
        Image.asset('assets/images/ic_next.png',width: 15.w,height: 15.w,color: Color_grey),
      ],
    );
  }
  Widget buildBankNum() {
    return Row(
      children: [
        Text('银行卡号',style: text_131732_14),
        Expanded(
          child: TextField(
            maxLength: 20,
            controller: controller.bankNumController,
            textAlign: TextAlign.right,
            style: text_131732_14,
            keyboardType: TextInputType.number,
            decoration: InputDecoration(
              prefixText: "  ",
              isDense: true,
              contentPadding: EdgeInsets.symmetric(vertical: 12.w),
              counterText: "", // 去掉底部计数
              enabledBorder:  const UnderlineInputBorder(borderSide: BorderSide.none), //无焦点时状态
              focusedBorder:  const UnderlineInputBorder(borderSide: BorderSide.none), //有焦点时状态
              hintText: '请输入银行卡号',
              hintStyle: text_grey_14,
            ),
          ),
        ),
      ],
    );
  }
  Widget buildPhone() {
    return Row(
      children: [
        Text('预留手机号',style: text_131732_14),
        Expanded(
          child: TextField(
            keyboardType: TextInputType.number,
            maxLength: 11,
            textAlign: TextAlign.right,
            controller: controller.phoneController,
            style: text_131732_14,
            decoration: InputDecoration(
              prefixText: "  ",
              isDense: true,
              contentPadding: EdgeInsets.symmetric(vertical: 12.w),
              counterText: "", // 去掉底部计数
              enabledBorder:  const UnderlineInputBorder(borderSide: BorderSide.none), //无焦点时状态
              focusedBorder:  const UnderlineInputBorder(borderSide: BorderSide.none), //有焦点时状态
              hintText: '请输入预留手机号',
              hintStyle: text_grey_14,
            ),
          ),
        ),
      ],
    );

  }
  Widget buildCode() {
    return  Row(
      children: [
        Text('短信验证码',style: text_131732_14),
        Expanded(
          child: TextField(
            maxLength: 20,
            keyboardType: TextInputType.number,
            controller: controller.codeController,
            textAlign: TextAlign.right,
            style: text_131732_14,
            decoration: InputDecoration(
              prefixText: "  ",
              isDense: true,
              contentPadding: EdgeInsets.symmetric(vertical: 12.w),
              counterText: "", // 去掉底部计数
              enabledBorder:  const UnderlineInputBorder(borderSide: BorderSide.none), //无焦点时状态
              focusedBorder:  const UnderlineInputBorder(borderSide: BorderSide.none), //有焦点时状态
              hintText: '请输入短信验证码',
              hintStyle: text_grey_14,
            ),
          ),
        ),
        SizedBox(width: 6.w),
        InkWell(
          onTap: () => controller.getCode(),
          child: Obx(()=>Container(
              padding: EdgeInsets.symmetric(horizontal: 9.w,vertical: 3.w),
              decoration: BoxDecoration(
                  color: controller.canGetCode.value ? Color_main :Color_line,
                  borderRadius: BorderRadius.all(Radius.circular(12.w))
              ),
              child: Text(controller.codeBtnStr.value,style: text_white_12)),
          ),
        )
      ],
    );
  }

}
